#454题.四数相加II
from typing import List
class Solution:
    def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:
        # a + b+ c +d = 0  a+b=-(c+d)
        count=0
        from collections import defaultdict
        dic=defaultdict(int)
         
        for a in nums1:
            for b in nums2:
                dic[a+b]+=1

        for c in nums3:
            for d in nums4:
                target = -(c+d)
                if target in dic:
                    count+=dic[target]

        return count